#!/bin/sh
# Periodically we should check for new keywords, update this list, and re-run the script.
# The script generates code that is used in squidb-processor's SqlUtils
declare -a sqlite_keywords=(
"ABORT"
"ACTION"
"ADD"
"AFTER"
"ALL"
"ALTER"
"ANALYZE"
"AND"
"AS"
"ASC"
"ATTACH"
"AUTOINCREMENT"
"BEFORE"
"BEGIN"
"BETWEEN"
"BY"
"CASCADE"
"CASE"
"CAST"
"CHECK"
"COLLATE"
"COLUMN"
"COMMIT"
"CONFLICT"
"CONSTRAINT"
"CREATE"
"CROSS"
"CURRENT_DATE"
"CURRENT_TIME"
"CURRENT_TIMESTAMP"
"DATABASE"
"DEFAULT"
"DEFERRABLE"
"DEFERRED"
"DELETE"
"DESC"
"DETACH"
"DISTINCT"
"DROP"
"EACH"
"ELSE"
"END"
"ESCAPE"
"EXCEPT"
"EXCLUSIVE"
"EXISTS"
"EXPLAIN"
"FAIL"
"FOR"
"FOREIGN"
"FROM"
"FULL"
"GLOB"
"GROUP"
"HAVING"
"IF"
"IGNORE"
"IMMEDIATE"
"IN"
"INDEX"
"INDEXED"
"INITIALLY"
"INNER"
"INSERT"
"INSTEAD"
"INTERSECT"
"INTO"
"IS"
"ISNULL"
"JOIN"
"KEY"
"LEFT"
"LIKE"
"LIMIT"
"MATCH"
"NATURAL"
"NO"
"NOT"
"NOTNULL"
"NULL"
"OF"
"OFFSET"
"ON"
"OR"
"ORDER"
"OUTER"
"PLAN"
"PRAGMA"
"PRIMARY"
"QUERY"
"RAISE"
"RECURSIVE"
"REFERENCES"
"REGEXP"
"REINDEX"
"RELEASE"
"RENAME"
"REPLACE"
"RESTRICT"
"RIGHT"
"ROLLBACK"
"ROW"
"SAVEPOINT"
"SELECT"
"SET"
"TABLE"
"TEMP"
"TEMPORARY"
"THEN"
"TO"
"TRANSACTION"
"TRIGGER"
"UNION"
"UNIQUE"
"UPDATE"
"USING"
"VACUUM"
"VALUES"
"VIEW"
"VIRTUAL"
"WHEN"
"WHERE"
"WITH"
"WITHOUT"
)

for i in "${sqlite_keywords[@]}"
do
   echo "create table $i ($i text primary key);" >> sqlite-keywords-test.sql
   echo "select 'ALL_KEYWORDS.add(\"$i\");' || (case (exists (select * from sqlite_master where type='table' and name='$i')) when 1 then '' else ' RESTRICTED_KEYWORDS.add(\"$i\");' end);" >> sqlite-keywords-test.sql
   echo "drop table $i;" >> sqlite-keywords-test.sql
done

sqlite3 testDatabase.db < sqlite-keywords-test.sql > keywords.txt
cat keywords.txt
rm testDatabase.db
rm sqlite-keywords-test.sql
rm keywords.txt
